package fi.piet.ec2.department;

import java.util.ArrayList;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.PageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import fi.piet.ec2.employee.Employee;
import fi.piet.ec2.service.EmployeeService;

public class EditDepartment extends WebPage {
	
	@SpringBean
	private EmployeeService employeeService;

	@SuppressWarnings("serial")
	public EditDepartment(Department depa) {
		
		ArrayList<Employee> empList = new ArrayList<Employee>(employeeService.findEmployeesForADepartment(depa));
		
		add(new ListView("employeeList", empList) {
			public void populateItem(final ListItem item) {
				final Employee employee = (Employee) item.getModelObject();
				item.add(new Label("firstname", employee.getFirstname()));
				item.add(new Label("lastname", employee.getLastname()));
			}
		});
		
		
		add(new DepartmentForm("editDepartmentForm", depa));
		add(new PageLink("departmentPageLink", DepartmentPage.class));
	}
}
